/**
 * @file implements ScriptLoader
 * @author CORSAR <vladimir.corsair@gmail.com>
 * @version 1.5.0
 */

/**
 * ScriptLoader
 * @param {type} resourcesList manifest.resources.scripts
 * @returns {ScriptLoader}
 */
var ScriptLoader = function (resourcesList) {
    this.resources = resourcesList;
};

/**
 * Load script resource
 * @param {type} id the id of source path in manifest.resources.scripts
 * @param {type} callback on load callback
 * @returns {undefined}
 */
ScriptLoader.prototype.load = function (id, callback) {
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    
    script.type = 'text/javascript';
    script.src = this.resources[id];

    script.onreadystatechange = callback ? callback.bind(this) : null;
    script.onload = callback ? callback.bind(this) : null;

    head.appendChild(script);
};